//城弹窗模块
define('city', ['config', 'jquery', 'handlebars'], function(config, $, Handlebars){

	return function(){
		var cities = {
			hot: ['全国', '北京', '上海', '广州', '深圳', '杭州', '成都'],
			provinces: [
				{
					"name":"直辖市",
					"cities":["北京","上海","天津","重庆"]
				},
				{
					"name":"广东省",
					"cities":["广州","汕尾","阳江","揭阳","茂名","惠州","江门","韶关","梅州","汕头","深圳","珠海","佛山","肇庆","湛江","中山","河源","清远","云浮","潮州","东莞"]
				},
				{
					"name":"河北省",
					"cities":["邯郸","石家庄","保定","张家口","承德","唐山","廊坊","沧州","衡水","邢台"]
				},
				{
					"name":"山西省",
					"cities":["朔州","忻州","太原","大同","阳泉","晋中","长治","晋城","临汾","吕梁","运城"]
				},
				{
					"name":"内蒙古自治区",
					"cities":["呼伦贝尔","呼和浩特","包头","乌海","乌兰察布","通辽","赤峰","鄂尔多斯","巴彦淖尔","锡林郭勒盟","兴安盟","阿拉善盟"]
				},
				{
					"name":"辽宁省",
					"cities":["沈阳","铁岭","大连","鞍山","抚顺","本溪","丹东","锦州","营口","阜新","辽阳","朝阳","盘锦","葫芦岛"]
				},
				{
					"name":"吉林省",
					"cities":["长春","吉林","延边朝鲜族自治州","四平","通化","白城","辽源","松原","白山"]
				},
				{
					"name":"黑龙江省",
					"cities":["哈尔滨","齐齐哈尔","鸡西","牡丹江","七台河","佳木斯","鹤岗","双鸭山","绥化","黑河","大兴安岭地区","伊春","大庆"]
				},
				{
					"name":"江苏省",
					"cities":["南京","无锡","镇江","苏州","南通","扬州","盐城","徐州","淮安","连云港","常州","泰州","宿迁"]
				},
				{
					"name":"浙江省",
					"cities":["舟山","衢州","杭州","湖州","嘉兴","宁波","绍兴","温州","丽水","金华","台州"]
				},
				{
					"name":"安徽省",
					"cities":["合肥","芜湖","蚌埠","淮南","马鞍山","淮北","铜陵","安庆","黄山","滁州","阜阳","宿州","巢湖","六安","亳州","池州","宣城"]
				},
				{
					"name":"福建省",
					"cities":["福州","厦门","宁德","莆田","泉州","漳州","龙岩","三明","南平"]
				},
				{
					"name":"江西省",
					"cities":["鹰潭","新余","南昌","九江","上饶","抚州","宜春","吉安","赣州","景德镇","萍乡"]
				},
				{
					"name":"山东省",
					"cities":["菏泽","济南","青岛","淄博","德州","烟台","潍坊","济宁","泰安","临沂","滨州","东营","威海","枣庄","日照","莱芜","聊城"]
				},
				{
					"name":"河南省",
					"cities":["商丘","郑州","安阳","新乡","许昌","平顶山","信阳","南阳","开封","洛阳","济源","焦作","鹤壁","濮阳","周口","漯河","驻马店","三门峡"]
				},
				{
					"name":"湖北省",
					"cities":["武汉","襄樊","鄂州","孝感","黄冈","黄石","咸宁","荆州","宜昌","恩施土家族苗族自治州","神农架林区","十堰","随州","荆门","仙桃","天门","潜江"]
				},
				{
					"name":"湖南省",
					"cities":["岳阳","长沙","湘潭","株洲","衡阳","郴州","常德","益阳","娄底","邵阳","湘西土家族苗族自治州","张家界","怀化","永州"]
				},
				{
					"name":"海南省",
					"cities":["海口","三亚","五指山","琼海","儋州","文昌","万宁","东方","澄迈县","定安县","屯昌县","临高县","白沙黎族自治县","昌江黎族自治县","乐东黎族自治县","陵水黎族自治县","保亭黎族苗族自治县","琼中黎族苗族自治县"]
				},{
					"name":"广西壮族自治区",
					"cities":["防城港","南宁","崇左","来宾","柳州","桂林","梧州","贺州","贵港","玉林","百色","钦州","河池","北海"]
				},
				{
					"name":"甘肃省",
					"cities":["兰州","金昌","白银","天水","嘉峪关","武威","张掖","平凉","酒泉","庆阳","定西","陇南","临夏回族自治州","甘南藏族自治州"]
				},
				{
					"name":"陕西省",
					"cities":["西安","咸阳","延安","榆林","渭南","商洛","安康","汉中","宝鸡","铜川"]
				},
				{
					"name":"新疆维吾尔自治区",
					"cities":["塔城地区","哈密地区","和田地区","阿勒泰地区","克孜勒苏柯尔克孜自治州","博尔塔拉蒙古自治州","克拉玛依","乌鲁木齐","石河子","昌吉回族自治州","五家渠","吐鲁番地区","巴音郭楞蒙古自治州","阿克苏地区","阿拉尔","喀什地区","图木舒克","伊犁哈萨克自治州"]
				},
				{
					"name":"青海省",
					"cities":["海北藏族自治州","西宁","海东地区","黄南藏族自治州","海南藏族自治州","果洛藏族自治州","玉树藏族自治州","海西蒙古族藏族自治州"]
				},
				{
					"name":"宁夏回族自治区",
					"cities":["银川","石嘴山","吴忠","固原","中卫"]
				},
				{
					"name":"四川省",
					"cities":["成都","攀枝花","自贡","绵阳","南充","达州","遂宁","广安","巴中","泸州","宜宾","资阳","内江","乐山","眉山","凉山彝族自治州","雅安","甘孜藏族自治州","阿坝藏族羌族自治州","德阳","广元"]
				},
				{
					"name":"贵州省",
					"cities":["贵阳","遵义","安顺","黔南布依族苗族自治州","黔东南苗族侗族自治州","铜仁地区","毕节地区","六盘水","黔西南布依族苗族自治州"]
				},
				{
					"name":"云南省",
					"cities":["西双版纳傣族自治州","德宏傣族景颇族自治州","昭通","昆明","大理白族自治州","红河哈尼族彝族自治州","曲靖","保山","文山壮族苗族自治州","玉溪","楚雄彝族自治州","普洱","临沧","怒江傈傈族自治州","迪庆藏族自治州","丽江"]
				},
				{
					"name":"西藏自治区",
					"cities":["拉萨","日喀则地区","山南地区","林芝地区","昌都地区","那曲地区","阿里地区"]
				},
				{
					"name":"台湾省",
					"cities":["台北","高雄","基隆","台中","台南","新竹","嘉义"]
				},
				{
					"name":"特别行政区",
					"cities":["澳门特别行政区", "香港特别行政区"]
				}
			]
		};

		var source = $('#city-template').html();
		var template = Handlebars.compile(source);
		$('#cityModal .modal-content').html(template(cities));

		$('#cityModal ul').on('click', 'span', function(){
			var $parent = $(this).parents('.modal-content');

			if ($(this).hasClass('active')){
				$(this).removeClass('active');
				$parent.find('.top h1').text('选择城市：');
				$parent.find('.top .main-submit').hide();
				$parent.find('.top .main-submit').attr('data-city', '');
			}
			else{
				$('#cityModal ul .active').removeClass('active');
				$(this).addClass('active');
				var name = $(this).text()
				$parent.find('h1').text('选择城市：' + name);
				$parent.find('.top .main-submit').css('display', 'inline-block');
				$parent.find('.top .main-submit').attr('data-city', $(this).text())
			}
		});
	}
});